package com.adinnet.api.classs.controller;


import com.adinnet.api.classs.model.vo.ClasssResp;
import com.adinnet.api.classs.service.ClasssService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.exception.BizException;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 班级名称 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-02
 */
@RestController
@RequestMapping("/api/classs")
public class ClasssController {

    @Autowired
    private ClasssService classsService;

    /**
     * 查询班级课程列表
     *
     * @return
     */
    @GetMapping("list")
    public JsonResult classsList(Integer classId,Integer childId ,HttpServletRequest request, HttpServletResponse response) {
        try {
            if (null == classId) {
                return JsonResult.error("班级Id不能为空");
            }
            if (null == childId) {
                return JsonResult.error("儿童childId不能为空");
            }
            List<ClasssResp> classsResps = classsService.classsList(classId,childId);
            if (CollectionUtils.isEmpty(classsResps)) {
                return JsonResult.ok().put("data", Lists.newArrayList());
            }
            return JsonResult.ok().put("data", classsResps);
        } catch (BizException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            return JsonResult.error("查询班级课程列表失败!");
        }
    }

    /**
     * 查看课程列表
     *
     * @return
     */
    @GetMapping("list/details")
    public JsonResult classsListDetails(Integer childId,Integer courseId, String type, HttpServletRequest request, HttpServletResponse response) {
        try {
            if(null==childId){
                return JsonResult.error("儿童Id不能为空");
            }
            if (null == courseId) {
                return JsonResult.error("课程Id不能为空");
            }
            if (StringUtils.isEmpty(type)) {
                return JsonResult.error("课程类型不能为空");
            }
            return classsService.classsListDetails(childId,courseId, type);

        } catch (BizException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            return JsonResult.error("查看课程列表失败!");
        }
    }
}
